var starttime = []
var geoDim = []// 地理纬度子集列表
var HB_province = '河北省'

var integrity_cell_fdd = []// fdd 小区完好度
var integrity_cell_tdd = []// tdd 小区完好度
var integrity_cell_starttime = []
var integrity_cell_geoDim = []

var ratio_online_tdd = []
var ratio_online_fdd = []
var ratio_online_geoDim = []

var withdrawal_ratio = []
var withdrawal_ratio_starttime = []
var withdrawal_ratio_geoDim = []

var num_close = []
var succ_close_ratio = []
var view_close_starttime = []

var inandoutdoor_cell_traffic_ratio = []

// var param = {}
N.maintenance2 = N.Class.extend({
    resize: function () {
        // var topheight = $('.container-fluid').height() - $('.content-header').height() - 5;
        var topheight = $('.container-fluid').height() - 20
        var bottomheight = topheight * (1 / 2)
        var boxtop = bottomheight - 120
        var maptop = topheight * (2 / 3) - 60
        var mapbot = topheight * (1 / 3) - 60
        $('.control-size-box').height(boxtop)
        $('.control-size-box-map').height(maptop)
        $('.control-size-box-mapbot').height(mapbot)

        var headheight = $('#table1_wrapper .dataTables_scrollHeadInner').height()
        if (headheight) {
            this.tablbeHeight = boxtop - headheight - 5
            $('#table1_wrapper .dataTables_scrollBody').height(this.tablbeHeight)
        }
        headheight = $('#table2_wrapper .dataTables_scrollHeadInner').height()
        if (headheight) {
            this.tablbeHeight = boxtop - headheight - 5
            $('#table2_wrapper .dataTables_scrollBody').height(this.tablbeHeight)
        }
    },
    pageLoad: function (geography, shiduan, geo_dim, city, area) {
        loading.show()
        if (geography) {
            this.geographyChart(shiduan, geo_dim, city, area)
        } else {
            this.timeChart(shiduan, geo_dim, city, area)
        }
        this.chartTop(shiduan, geo_dim, city, area)
    },
    chartTop: function (shiduan, geo_dim, city, area) {
        if (geo_dim === '省') {
            param = {
                geo_dim: geo_dim,
                time_dim: shiduan,
                area: area
            }
        } else {
            param = {
                geo_dim: geo_dim,
                time_dim: shiduan,
                city: city,
                area: area
            }
        }
        param.isChartTop = 'true'
        service.get(getApiPath() + 'maintenance/geographyChart',
            {
                params: param
            }
        ).then(function (res) {
            try {
                processGeograRes(res.data)
            } catch (e) {
                console.log(e)
            }
        }).catch(function (e) {
            console.log(e)
            return false
        })
    },
    geographyChart: function (shiduan, geo_dim, city, area) {
        if (geo_dim === '省') {
            param = {
                geo_dim: '地市',
                time_dim: shiduan,
                area: area
            }
        } else if (geo_dim === '地市' || geo_dim === '区县') {
            param = {
                geo_dim: '区县',
                time_dim: shiduan,
                city: city,
                area: area != '全量小区' ? area : ''
            }
        }
        getWideData(param, 'maintenance/geographyChart')
    },
    timeChart: function (shiduan, geo_dim, city, area) {
        if (geo_dim === '省') {
            param = {
                geo_dim: geo_dim,
                time_dim: shiduan,
                area: area,
                num: shiduan == 'M' ? 6 : 7
            }
        } else {
            param = {
                geo_dim: geo_dim,
                time_dim: shiduan,
                city: city,
                area: area,
                num: shiduan == 'M' ? 6 : 7
            }
        }
        getWideData(param, 'maintenance/timeChart')
    }
})
var page = new N.maintenance2()
function check (val, el) {
    if (val > 0) {
        el.next('i').removeClass('fa-long-arrow-up').removeClass('fa-long-arrow-down').addClass('fa-long-arrow-up').css('color', '#f83608')
    } else if (val < 0) {
        el.next('i').removeClass('fa-long-arrow-up').removeClass('fa-long-arrow-down').addClass('fa-long-arrow-down').css('color', '#46d51a')
    } else {
        el.next('i').removeClass('fa-long-arrow-up').removeClass('fa-long-arrow-down')
    }
}
$(function () {
    loading.show()
    $(document).on('map:click', function (event, geography, shiduan, geo_dim, map_city, map_area) {
        page.pageLoad(geography, shiduan, geo_dim, map_city, map_area)
    })
})

function cleanRes () {
    integrity_cell_fdd = []
    integrity_cell_tdd = []
    integrity_cell_starttime = []
    integrity_cell_geoDim = []

    ratio_online_tdd = []
    ratio_online_fdd = []
    ratio_online_geoDim = []

    withdrawal_ratio = []
    withdrawal_ratio_starttime = []
    withdrawal_ratio_geoDim = []

    num_close = []
    succ_close_ratio = []
    view_close_starttime = []

    inandoutdoor_cell_traffic_ratio = []

    starttime = []
    geoDim = []
}

function getWideData (param, reqUrl) {
    console.log('时间维度:' + param.time_dim + '；地理纬度:' + param.geo_dim + '；省:' + HB_province + '；市:' + param.city + '；区县:' + param.area + '；请求地址:' + reqUrl)
    loading.show()
    service.get(getApiPath() + reqUrl,
        {
            params: param
        }
    ).then(function (result) {
        cleanRes()
        try {
            // 小区完好度(静态) 废弃于 20191107
            /* var integrity_cell_list = result.data.a_pm_manager_view_integrity_cell_list;
            integrity_cell_list.reverse();
            integrity_cell_list.filter(function (item) {
                if ("FDD" === item.eutran_type) {
                    integrity_cell_fdd.push(parseFloat(item.integrity_cell))
                    // item.city === '全省' ? integrity_cell_geoDim.push(item.city) : integrity_cell_geoDim.push("");
                    integrity_cell_geoDim.push(item.city);
                    integrity_cell_starttime.push(item.starttime.substr(5, 5));
                }
                if ("TDD" === item.eutran_type) {
                    integrity_cell_tdd.push(parseFloat(item.integrity_cell))
                }
            }); */

            // 无线设备在网率
            var online_ratio_list = result.data.a_pm_manager_view_online_ratio_list
            online_ratio_list.reverse()
            online_ratio_list.filter(function (item) {
                if (item.city != '全省') {
                    ratio_online_fdd.push(parseFloat(item.ratio_online_fdd))
                    ratio_online_tdd.push(parseFloat(item.ratio_online_tdd))
                    ratio_online_geoDim.push(item.city)
                }
            })

            // 退服小区占比
            var withdrawal_ratio_list = result.data.a_pm_manager_view_withdrawal_ratio_list
            withdrawal_ratio_list.reverse()
            withdrawal_ratio_list.filter(function (item) {
                withdrawal_ratio.push(parseFloat(item.withdrawal_ratio))
                // item.city === '全省' ? withdrawal_ratio_geoDim.push(item.city) : withdrawal_ratio_geoDim.push("");
                withdrawal_ratio_geoDim.push(item.city)
                withdrawal_ratio_starttime.push(item.starttime.substr(5, 5))
            })

            // 小区关断/解关断成功率
            var close_list = result.data.a_pm_manager_view_close_list
            close_list.reverse()
            close_list.filter(function (item) {
                num_close.push(parseInt(item.num_close))
                succ_close_ratio.push(parseFloat(item.succ_close_ratio))
                view_close_starttime.push(item.starttime.substr(5, 5))
            })

            // 4G室分流量承载比
            var widetable_new_list = result.data.a_pm_manager_view_widetable_new_list
            widetable_new_list.reverse()
            widetable_new_list.filter(function (value) {
                if (value.city != '不详' && value.area != '不详') {
                    if (value.area === '全量小区') {
                        geoDim.push(value.city)
                    } else {
                        geoDim.push(value.area)
                    }
                    inandoutdoor_cell_traffic_ratio.push(value.inandoutdoor_cell_traffic_ratio)
                    // 小区完好度 静态变为动态 20191107 开始
                    integrity_cell_tdd.push(parseFloat(value.num13))
                    integrity_cell_fdd.push(parseFloat(value.num14))
                    // 小区完好度 静态变为动态 20191107 结束
                    starttime.push(value.starttime.substr(5, 5))
                }
            })
        } catch (e) {
            console.log('数据处理异常' + e)
        }
        drawPage()
        loading.hide()
    }).catch(function (e) {
        console.log(e)
        return false
    })
}

function drawPage () {
    // 小区完好度
    drawColumnCol({
        id: 'line1',
        title: null,
        cate: $('#showFont').attr('geography') ? geoDim : starttime,
        data: [
            {
                name: 'TDD小区完好度(%)',
                type: 'column',
                maxPointWidth: 10,
                data: integrity_cell_tdd,
                yAxis: 0
            }, {
                name: 'FDD小区完好度(%)',
                type: 'column',
                maxPointWidth: 10,
                data: integrity_cell_fdd,
                yAxis: 1
            }
        ],
        marginTop: 30,
        marginBottom: 0,
        itemWidth: 110,
        lenabled: true,
        lenabledAlign: 'center',
        lenabledVerticalAlign: '',
        layout: 'horizontal',
        lenabledWidth: 10,
        chartType: 'column'
        // Yfloor: Math.max.apply(Math, upoct) * 0.2,
        // Yfloor2: Math.max.apply(Math, volte_voice_traffic) * 0.2

    })
    // 无线设备再用率
    drawColumnCol({
        id: 'line2',
        title: null,
        cate: ratio_online_geoDim,
        data: [
            {
                name: 'TDD无线设备在网率(%)',
                type: 'column',
                maxPointWidth: 10,
                data: ratio_online_tdd,
                yAxis: 0
            }, {
                name: 'FDD无线设备在网率(%)',
                type: 'column',
                maxPointWidth: 10,
                data: ratio_online_fdd,
                yAxis: 1
            }
        ],
        marginTop: 30,
        marginBottom: 0,
        itemWidth: 110,
        lenabled: true,
        lenabledAlign: 'center',
        lenabledVerticalAlign: '',
        layout: 'horizontal',
        lenabledWidth: 10,
        chartType: 'column'
        // Yfloor: Math.max.apply(Math, upoct) * 0.2,
        // Yfloor2: Math.max.apply(Math, volte_voice_traffic) * 0.2

    })
    // 退服小区占比
    drawColumnCol({
        id: 'line3',
        title: null,
        cate: $('#showFont').attr('geography') ? withdrawal_ratio_geoDim : withdrawal_ratio_starttime,
        data: [
            {
                name: '超24小时退服基站占比(%)',
                data: withdrawal_ratio,
                type: 'areaspline',
                // color: N.Util.Theme_colors.blue,
                fillOpacity: 0.3, // 指定面积图的透明度
                marker: {
                    enabled: true,
                    symbol: 'circle',
                    radius: 2
                }
            }
        ],
        marginTop: 30,
        marginBottom: 0,
        itemWidth: 110,
        lenabled: true,
        lenabledAlign: 'center',
        lenabledVerticalAlign: '',
        layout: 'horizontal',
        lenabledWidth: 10,
        chartType: 'column'
        // Yfloor: Math.max.apply(Math, upoct) * 0.2,
        // Yfloor2: Math.max.apply(Math, volte_voice_traffic) * 0.2

    })
    // 4G室分流量承载比
    drawColumnCol({
        id: 'line4',
        title: null,
        cate: $('#showFont').attr('geography') ? geoDim : starttime,
        data: [
            {
                name: '4G室分流量承载比(%)',
                data: inandoutdoor_cell_traffic_ratio,
                type: 'areaspline',
                // color: N.Util.Theme_colors.blue,
                fillOpacity: 0.3, // 指定面积图的透明度
                marker: {
                    enabled: true,
                    symbol: 'circle',
                    radius: 2
                }
            }
        ],
        marginTop: 30,
        marginBottom: 0,
        itemWidth: 110,
        lenabled: true,
        lenabledAlign: 'center',
        lenabledVerticalAlign: '',
        layout: 'horizontal',
        lenabledWidth: 10,
        chartType: 'column'
        // Yfloor: Math.max.apply(Math, upoct) * 0.2,
        // Yfloor2: Math.max.apply(Math, volte_voice_traffic) * 0.2

    })
    // 小区关断/解关断成功率
    drawColumnColMax({
        id: 'line5',
        title: null,
        cate: view_close_starttime,
        data: [
            {
                name: '关断小区数',
                type: 'column',
                maxPointWidth: 10,
                data: num_close,
                yAxis: 0
            }, {
                name: '解关断成功率(%)',
                type: 'line',
                marker: {
                    enabled: true, /* 数据点是否显示 */
                    radius: 4 /* 数据点大小px */
                },
                data: succ_close_ratio,
                yAxis: 1
            }
        ],
        marginTop: 30,
        marginBottom: 0,
        itemWidth: 110,
        lenabled: true,
        lenabledAlign: 'center',
        lenabledVerticalAlign: '',
        layout: 'horizontal',
        lenabledWidth: 10,
        chartType: 'column',
        // Yfloor: Math.max.apply(Math, upoct) * 0.2,
        Yfloor2: 50,
        YMax2: 100

    })

    loading.hide()
}
/**
 * @Author:         yyj
 * @CreateDate:     2019/10/31 15:31
 * @Description:    处理地理纬度标题数据
 */
function processGeograRes (result) {
    // 小区完好度 废弃于20191107
    /* var integrity_cell_list = result.a_pm_manager_view_integrity_cell_list;
    if(integrity_cell_list[0].eutran_type === 'TDD'){
        $("#integrity_cell_tdd").text(integrity_cell_list[0].integrity_cell);
        $("#integrity_cell_fdd").text(integrity_cell_list[1].integrity_cell);
    }
    if(integrity_cell_list[0].eutran_type === 'FDD'){
        $("#integrity_cell_fdd").text(integrity_cell_list[0].integrity_cell);
        $("#integrity_cell_tdd").text(integrity_cell_list[1].integrity_cell);
    } */

    // 无线设备在网率
    var online_ratio_list = result.a_pm_manager_view_online_ratio_list
    $('#ratio_online_tdd').text(online_ratio_list[0].ratio_online_tdd)
    $('#ratio_online_fdd').text(online_ratio_list[0].ratio_online_fdd)

    // 退服小区占比
    var withdrawal_ratio_list = result.a_pm_manager_view_withdrawal_ratio_list

    // 小区关断/解关断成功率
    var close_list = result.a_pm_manager_view_close_list
    $('#num_close').text(close_list[0].num_close)
    $('#succ_close_ratio').text(close_list[0].succ_close_ratio)

    // 4G室分流量承载比
    result = result.a_pm_manager_view_widetable_new_list
    result.reverse()

    $('#indoor_cell_traffic').text(toThousands(result[0].indoor_cell_traffic ? result[0].indoor_cell_traffic.toFixed(2) : 0))// 室分
    $('#outdoor_cell_traffic').text(toThousands(result[0].outdoor_cell_traffic ? result[0].outdoor_cell_traffic.toFixed(2) : 0))// 宏站
    $('#inandoutdoor_cell_traffic_ratio').text(result[0].inandoutdoor_cell_traffic_ratio ? result[0].inandoutdoor_cell_traffic_ratio.toFixed(2) : 0)// 宏站室分比

    // 小区完好度调整为动态 20191107
    $('#integrity_cell_tdd').text(result[0].num13)
    $('#integrity_cell_fdd').text(result[0].num14)
}
